# Definition for a binary tree node.
class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None


class Solution:
    def maxDepth(self, root: TreeNode) -> int:
        self.res = 0
        if root:
            self.search(root, 1)
        return self.res

    def search(self, root_in: TreeNode, deepth: int):
        if root_in.left:
            self.search(root_in.left, deepth+1)
        if root_in.right:
            self.search(root_in.right, deepth+1)
        self.res = max(self.res, deepth)
